package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.SysDictData;
import io.mybatis.example.springboot.service.SysDictDataService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * sys_dict_data - 字典数据表
 *
 * @author mkj
 */
@RestController
@RequestMapping("sysDictDatas")
public class SysDictDataController {

  @Autowired
  private SysDictDataService sysDictDataService;

  @PostMapping
  public DataResponse<SysDictDataDO> save(@RequestBody SysDictDataDO sysDictData) {
    return DataResponse.ok(sysDictDataService.save( sysDictData));
  }

  @GetMapping
  public RowsResponse<SysDictDataDO> findList(@RequestBody SysDictDataDO sysDictData) {
    return RowsResponse.ok(sysDictDataService.findList( sysDictData));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<SysDictDataDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysDictDataService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<SysDictDataDO> update(@PathVariable("id") Long id, @RequestBody SysDictDataDO sysDictData) {
    sysDictData.setId(id);
    return DataResponse.ok(sysDictDataService.update( sysDictData));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysDictDataService.deleteById(id) == 1);
  }

}
